$.fn.eCollapse = function(options) {
    return this.each(function() {
        const eCollapse =  new ECollapse(this, options)
        $(this).data('eCollapse', eCollapse)
    })
}


function ECollapse(el, options) {
    this.$el = $(el)
    this.$head = this.$el.find('.collapse-item-head')
    this.$arrow = this.$el.find('.collapse-item__arrow')
    this.$content = this.$el.find('.collapse-item-content')
    this.options = options
    this.init()
    this.initEvents()
}

ECollapse.prototype = {
    init: function() {
        this.setCollapsed(false)

    },
    initEvents: function() {
        const _this = this
        this.$head.on('click', function () {
            _this.setCollapsed(!_this.isCollapsed)
        })
    },
    setCollapsed: function(isCollapsed) {
        this.isCollapsed = isCollapsed

        if(isCollapsed) {

            this.$arrow.removeClass('is-active')
            this.$content.slideUp(300, 'linear')
        } else {
            // 展开
            this.$arrow.addClass('is-active')

            this.$content.slideDown(300, 'linear')
        }
    }
}